
/**
* 选择日期时间
*parammeter: ename:所选择填日期时间
*parammeter: compareSource:所比较的日期时间
*parammeter: compareType:比较类型： g:必须比所比较的日期大； l:必须比所比较的日期小；e:必须和所比较的日期相等
*                                ge:必须大于等于所比较的日期  le:必须小于等于所比较的日期; ne:必须不等于所比较日期
*parammeter: alerStr:比较条件不满足时弹出的警告信息
* 新增类型 compareType=b;日期必须在compareSource和compareSource2之间
*/
function ev_setCompdatetime(ename,compareSource,compareType,alerStr,compareSource2){
  // var selectdate = window.showModalDialog('/js/common/dailyTime.htm',window,'dialogHeight:280px;dialogWidth:210px;status=off');
   var selectdate = calendar();
  
   var compareValue="";
   if(document.all(compareSource).value != null && document.all(compareSource).value.length >0)
     {compareValue=document.all(compareSource).value;}
   if(selectdate!=""&&selectdate!=undefined&&compareType!="" && compareType!=undefined&&compareValue!="" && compareValue!=undefined)
   {
    
    if(compareType=='g')
     {
      if(compareDateTime(selectdate,compareValue)>0)
        {
         if (selectdate != "" && selectdate !=undefined) document.all(ename).value=selectdate;
        }
      else{
          alert(alerStr);
          return;
      }  
     }
    else if(compareType=='l')
     {
      if(compareDateTime(selectdate,compareValue)<0)
        {
         if (selectdate != "" && selectdate !=undefined) document.all(ename).value=selectdate;
        }
      else{
          alert(alerStr);
          return;
      }  
     }
    else if(compareType=='e')
     {
      if(compareDateTime(selectdate,compareValue)==0)
        {
         if (selectdate != "" && selectdate !=undefined) document.all(ename).value=selectdate;
        }
      else{
           alert(alerStr);
          return;
      }  
     }   
     else if(compareType=='ge')
     {
      if(compareDateTime(selectdate,compareValue)>=0)
        {
         if (selectdate != "" && selectdate !=undefined) document.all(ename).value=selectdate;
        }
      else{
          alert(alerStr);
          return;
      }  
     } 
     else if(compareType=='le')
     {
      if(compareDateTime(selectdate,compareValue)<=0)
        {
         if (selectdate != "" && selectdate !=undefined) document.all(ename).value=selectdate;
        }
      else{
          alert(alerStr);
          return;
      }  
     }       
     else if(compareType=='ne')
     {
      if(compareDateTime(selectdate,compareValue)!=0)
        {
         if (selectdate != "" && selectdate !=undefined) document.all(ename).value=selectdate;
        }
      else{
          alert(alerStr);
          return;
      }  
     }        
   }   
   else
   {if (selectdate != "" && selectdate !=undefined) document.all(ename).value=selectdate;}
}
function compareDateTime(date1,date2){
    	var year1 = date1.substring(0,date1.indexOf("-"));
    	var month1 = date1.substring(5,date1.lastIndexOf("-"));
    	var day1 = date1.substring(date1.lastIndexOf("-")+1,10);
        var hour1=date1.substring(date1.indexOf(" ")+1,date1.indexOf(":"));
        var minute1=date1.substring(date1.lastIndexOf(":")+1,date1.length);
    	var year2 = date2.substring(0,date2.indexOf("-"));
    	var month2 = date2.substring(5,date2.lastIndexOf("-"));
    	var day2 = date2.substring(date2.lastIndexOf("-")+1,10);
        var hour2=date2.substring(date2.indexOf(" ")+1,date2.indexOf(":"));
        var minute2=date2.substring(date2.lastIndexOf(":")+1,date2.length);   	
    	if(year1 == year2 && month1 == month2 && day1 == day2&& hour1 == hour2 && minute1 == minute2)	return 0;        	   	
    	else if(year1>year2 || (year1==year2 && month1>month2) ||(year1==year2 && month1==month2&&day1>day2)||(year1==year2 && month1==month2&&day1==day2&&hour1>hour2)||(year1==year2 && month1==month2&&day1==day2&&hour1==hour2&&minute1>minute2)) return 1;
    	else return -1;  
	}
/**
* 选择日期
*parammeter: ename:所选择填日期
*parammeter: compareSource:所比较的日期时间
*parammeter: compareType:比较类型： g:必须比所比较的日期大； l:必须比所比较的日期小；e:必须和所比较的日期相等
*                                ge:必须大于等于所比较的日期  le:必须小于等于所比较的日期; ne:必须不等于所比较日期
*parammeter: alerStr:比较条件不满足时弹出的警告信息
*/
function ev_setCompdate(ename,compareSource,compareType,alerStr,compareSource2){
   //var selectdate = window.showModalDialog('/js/common/Calendar.htm',window,'dialogHeight:180px;dialogWidth:185px;status=off');
    var selectdate = document.all(ename).value;
    
   var compareValue="";
  
   if(document.all(compareSource).value != null && document.all(compareSource).value.length >0)
     {compareValue=document.all(compareSource).value;}
   if(selectdate!=""&&selectdate!=undefined&&compareType!="" && compareType!=undefined&&compareValue!="" && compareValue!=undefined)
   {
    
    if(compareType=='g')
     {
      if(compareDate(selectdate,compareValue)<=0)
        {
          alert(alerStr);
          return;
      }  
     }
    else if(compareType=='l')
     {
      if(compareDate(selectdate,compareValue)>=0)
        {
          alert(alerStr);
          return;
      }  
     }
    else if(compareType=='e')
     {
      if(compareDate(selectdate,compareValue)!=0)
        {
           alert(alerStr);
          return;
      }  
     }   
     else if(compareType=='ge')
     {
      if(compareDate(selectdate,compareValue)<0)
        {
          alert(alerStr);
          return;
      }  
     } 
     else if(compareType=='le')
     {
      if(compareDate(selectdate,compareValue)>0)
        {
          alert(alerStr);
          return;
      }  
     }       
     else if(compareType=='ne')
     {
      if(compareDate(selectdate,compareValue)==0)
        {
          alert(alerStr);
          return;
      }  
     }
     else if(compareType=='b')
     {
      var compareValue2="";
      if(document.all(compareSource2).value != null && document.all(compareSource2).value.length >0)
         {compareValue2=document.all(compareSource2).value;}
      if(compareDate(selectdate,compareValue)>0&&compareDate(selectdate,compareValue2)<0)
      {   ;
      }
      else
      {
      alert(alerStr);
      return;} 
     }       
   }
   else  if(compareType=='b'&&document.all(compareSource2).value != null && document.all(compareSource2).value.length >0)
     {
      var compareValue2=document.all(compareSource2).value;
      if (compareDate(selectdate,compareValue2)<0)
       {  ;
        }
      else
       {alert(alerStr);return;}
       
     }   
   if(compareType=='b') 
   {   
     if (selectdate != "" && selectdate !=undefined) 
         document.all(ename).value=selectdate;
      dateItemControl(ename,compareSource,compareType,alerStr,compareSource2);    
        return;
   }
   if (selectdate != "" && selectdate !=undefined) 
       document.all(ename).value=selectdate;
}
 function compareDate(date1,date2)
 {
        if(date1==''||date2=='') return -2;
    	var year1 = date1.substring(0,date1.indexOf("-"));
    	var month1 = date1.substring(5,date1.lastIndexOf("-"));
    	var day1 = date1.substring(date1.lastIndexOf("-")+1,date1.length);

    	var year2 = date2.substring(0,date2.indexOf("-"));
    	var month2 = date2.substring(5,date2.lastIndexOf("-"));
    	var day2 = date2.substring(date2.lastIndexOf("-")+1,date2.length);
    	if(day2.length==1) day2=0+day2;
    	if(month2.length==1) month2=0+month2;
    	if(day1.length==1) day1=0+day1;
    	if(month1.length==1) month1=0+month1;    
    	if(year1 == year2 && month1 == month2 && day1 == day2)	return 0;    
    	else if(year1>year2 || (year1==year2 && month1>month2) ||(year1==year2 && month1==month2&&day1>day2)) return 1;
    	else return -1;  
	}